开发的时候碰到这样一个需求:需要从手机浏览器网页中启动自己的 App ,这样的代码网上一搜就是。于是我就模仿着写:
<intent-filter>
<data android:scheme="Test"/>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.BROWSABLE"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
手机本地测试网页 test.html 的代码:
<a href="Test://param">Click</a>
代码这样写应该没有问题了,可是运行发现启动不了自己的 App ,在网上查了好久。观察发现网上定义的 scheme 都是小写字母的形式,感觉问题可能出在 android:scheme=”Test” 。测试把 android:scheme=”Test” 改为 android:scheme=”test” 后,果然成功了。
上网查阅发现,Andoroid 官方要求 scheme 是小写字母的形式:
Note: Scheme matching in the Android framework is case-sensitive, unlike the RFC. As a result, you should always specify schemes using lowercase letters.